package test;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

public class Demo409 {

    public static void main(String[] args) {
        int abbc = longestPalindrome("aabbc");

        System.out.println(abbc);
    }

    public static int longestPalindrome(String s) {
        Map<Character, Integer> map = new HashMap<>();
        char[] chars = s.toCharArray();

        for (int i = 0; i < chars.length; i++) {
            map.put(chars[i], map.getOrDefault(chars[i], 0) + 1);
        }

        AtomicInteger count = new AtomicInteger();
        AtomicBoolean flag = new AtomicBoolean(false);
        map.values().forEach(integer -> {
            if(integer % 2 == 1){
                count.set(count.get() + integer-1);
                flag.set(true);
            }else {
                count.set(count.get() + integer);
            }
        });
        return flag.get() == true ? count.get() + 1 : count.get();
    }
}
